
import { BuiltInData } from '../../Config/tableOptions'
import { BaseFormButton } from '../../Utils/TableButton'
import { commonTableList } from '../../Config/tableCommon'
import { SelectModal, SelectDateModal, RenderDate } from '../../Template/ProTableOptions'


// TODO 入参 uuid, url, ProTableEvent, ClientData, Permission, actionRef
const Api = async ({ url, ProTableEvent, actionRef }) => {
    const get = `get${url}`
    const pos = `pos${url}`
    const put = `put${url}`
    const del = `del${url}`

    const initialValues = { isEnabled: 1 }


    const options = () => {
        return ([
            <BaseFormButton
                key='add'
                event='NewAdd'
                ProTableEvent={ProTableEvent}
                type="primary"
                icon="add"
                title="新增"
                data={{ params: { pos, put, initialValues, columns } }}
            />
        ])
    }
    const columns = [
        { ...commonTableList.SearchSort, selectType: 'Api' },
        commonTableList.uuid,
        { ...commonTableList.tableName, title: '接口名称' },
        {
            dataIndex: 'createTime',
            title: '时间测试',
            valueType: 'date',
            picker: 'date',
            // showTime: true,
            ellipsis: true,
            rules: true,
            width: 200,
            renderFormItem: ({ originProps }) => < SelectDateModal originProps={originProps} />,
            render: (_, e) => <RenderDate date={e.createTime} picker='date' showTime />
        },
        // {
        //     ...commonTableList.parentUuid,
        //     dataIndex: 'ProjectUuid',
        //     fieldProps: {
        //         fieldNames: { label: 'tableName', value: 'uuid' },
        //         options: Menu,
        //     },
        // },
        {
            dataIndex: 'controller',
            title: '控制器名称',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 200,
            hideInSearch: true
        },
        {
            dataIndex: 'method',
            title: '方法名称',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 200,
            hideInSearch: true
        },
        {
            dataIndex: 'targetUrl',
            title: '接口地址',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 200,
            hideInSearch: true
        },
        {
            dataIndex: 'httpMethod',
            title: '请求方式',
            rules: true,
            valueType: 'select',
            ellipsis: true,
            width: 150,
            hideInSearch: true,
            valueEnum: BuiltInData.RequestType,
            renderFormItem: ({ originProps }) => <SelectModal options={originProps.valueEnum} />,
        },
        commonTableList.code,
        commonTableList.sortId,
        commonTableList.isEnabled,
        {
            title: '操作',
            valueType: 'systemOperation',
            fixed: 'right',
            width: 240,
            align: 'center',
            hideInSearch: true,
            hideInAdded: true,
            hideInModify: true,
            render: (_, record) => {
                const { uuid } = record
                return [
                    <BaseFormButton
                        key='A01'
                        event='Modify'
                        ProTableEvent={ProTableEvent}
                        title="修改"
                        data={{ params: { pos, put, initialValues, columns }, record }}
                    />,
                    <BaseFormButton
                        key='delete'
                        event='Delete'
                        ProTableEvent={ProTableEvent}
                        title="删除"
                        danger
                        data={{ url: del, path: [uuid], actionRef }}
                    />,
                    // 二级页
                    // < BaseFormButton
                    //     key='A03'
                    //     event='OpenTwo'
                    //     ProTableEvent={ProTableEvent}
                    //     title="摄像头列表"
                    //     data={{ page: 'Device', record, header: columns }}
                    // />,
                    // // 固定数据
                    // < BaseFormButton
                    //     key='A03'
                    //     event='OpenEdit'
                    //     ProTableEvent={ProTableEvent}
                    //     title="固定数据"
                    //     data={{ page: ProjectData({ record }), record, header: columns }}
                    // />,
                    // // 附件
                    // < BaseFormButton
                    //     key='A01'
                    //     event='Annex'
                    //     ProTableEvent={ProTableEvent}
                    //     title="查看附件"
                    //     data={{ url: fileUrl }}
                    // />,
                ]
            },
        },
    ]



    return {
        get,
        columns,
        // hideInSearch: true,
        params: { pageIndex: 1, pageSize: 10 },
        // independenceSet: profile[url] ? profile[url]['independenceSet'] : false,
        options
    }
}

export default Api